import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'


// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
    VueSetupExtend()
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:8080', // 目标后端服务器地址
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/api/, ''), // 去掉 /user 前缀
      },
      '/resource': {
        target: 'http://localhost:8002', // 目标后端服务器地址 2
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/resource/, ''), // 去掉 /resource 前缀
      },
      '/course': {
        target: 'http://localhost:8001', // 目标后端服务器地址 2
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/course/, ''), // 去掉 /course 前缀
      },
    },
  }
})



